<?php
class Request {

    public $get = array();

    public $post = array();

    public $cookie = array();

    public $files = array();

    public $server = array();

    public $session = array();

    static $class;

    static public function __Auto()
    {

        if (!(self::$class instanceof self)) {
            self::$class = new Request();
        }
        return self::$class;
    }

    private function __construct()
    {

        $this->get = $this->clean($_GET);
        $this->post = $this->clean($_POST);
        $this->cookie = $this->clean($_COOKIE);
        $this->files = $this->clean($_FILES);
        $this->server = $this->clean($_SERVER);
        $this->session = $this->clean($_SESSION);
        unset($_GET, $_POST, $_COOKIE, $_FILES, $_SERVER);
    }

    public function clean(&$data)
    {

        if (is_array($data)) {
            foreach ($data as $key => &$value) {
                $data[$key] = $this->clean($value);
            }
        } else {
            $data = htmlspecialchars($data, ENT_QUOTES, 'UTF-8');
        }
        
        return $data;
    }

    public function set($request, $key, $value)
    {

        if (!isset($this->$request))
            return false;
        switch ($request) {
            case 'get' :
                $_GET[$key] = $value;
                break;
            case 'post' :
                $_POST[$key] = $value;
                break;
            case 'cookie' :
                $_COOKIE[$key] = $value;
                break;
            case 'files' :
                $_FILES[$key] = $value;
                break;
            case 'server' :
                $_SERVER[$key] = $value;
                break;
            case 'session' :
                $_SESSION[$key] = $value;
                break;
            default :
                return false;
                break;
        }
        $this->$request[$key] = $value;
        return true;
    
    }

    public function __destruct()
    {

        unset($_GET, $_POST, $_COOKIE, $_FILES, $_SERVER);
    }
}
?>